﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace SuperFox
{
    public partial class Product : UserControl
    {

        public static readonly DependencyProperty TitleProperty =
          DependencyProperty.Register("Title", typeof(String), typeof(Product),
                new PropertyMetadata("", new PropertyChangedCallback(TitlePropertyChanged)));

        public static readonly DependencyProperty ImageProperty =
            DependencyProperty.Register("Image", typeof(ImageBrush), typeof(Product), new PropertyMetadata(null,
                                                new PropertyChangedCallback(ImagePropertyChanged)));

        public static readonly DependencyProperty LinksProperty =
            DependencyProperty.Register("Links", typeof(Grid), typeof(Product), new PropertyMetadata(null,
                                                new PropertyChangedCallback(LinksPropertyChanged)));


        public Grid Links
        {
            get { return (Grid)GetValue(LinksProperty); }
            set { SetValue(LinksProperty, value); }
        }

        public String Title
        {
            get { return (String)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        public ImageBrush Image
        {
            get { return (ImageBrush)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }



        private static void LinksPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Grid g = e.NewValue as Grid;

            g.SetValue(Grid.ColumnProperty, 1);
            g.SetValue(Grid.RowProperty, 1);

            (d as Product).LayoutRoot.Children.Add(g);
        }


        private static void ImagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as Product).ImageCanvas.Background = e.NewValue as ImageBrush;
        }

        private static void TitlePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as Product).TitleBlock.Text = e.NewValue as String;
        }


        public Product()
        {
            InitializeComponent();
        }
    }
}
